<?php
require "class_Thumbnail.php";

	class Img{
	
		private $mime_type = array ("image/jpeg","image/gif", "image/png");

		public function __construct ($file){
			if ($this -> secure($file)){
				$this -> imgClassLoad($file);																	//Thumbnail class load
			//	return move_uploaded_file($file['tmp_name'],$this -> dir.'/'.$file['name']);
			}
			else echo "security error";
		}
		
		private function secure ($file){
				$blacklist = array (".html",".php");
				foreach ($blacklist as $item){
					if (preg_match ("/$item\$/i",$file['name'])){
						echo "ext error";
						return false;
					}
				}

				$type = $file['type'];
				for ($i=0;$i<count($this -> mime_type);$i++){
					if ($type == $this -> mime_type[$i]) break;
					if ($i + 1 == count ($this -> mime_type)) {
						echo "type error";
						return false;
					}
				}

				if ($file['size'] > 1024000){
					echo "size error";
					return false;
				}
			return true;
		}
		
		private function imgClassLoad($file){
			$tmb = new Thumbnail($file);
			unset ($tmb);
		}
	}
?>